"""add_system_integration_extend_fields

Revision ID: 011_system_integration_fields
Revises: 010_system_integration_extend
Create Date: 2025-04-01 00:01:00.000000

"""
from alembic import op
from models import db, types
import sqlalchemy as sa
from sqlalchemy.engine.reflection import Inspector
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '011_system_integration_fields'
down_revision = '010_system_integration_extend'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    conn = op.get_bind()
    inspector = Inspector.from_engine(conn)
    tables = inspector.get_table_names()
    
    if 'system_integration_extend' in tables:
        with op.batch_alter_table('system_integration_extend', schema=None) as batch_op:
            batch_op.add_column(sa.Column('test', sa.Boolean(), server_default=sa.text('false'), nullable=True, comment='是否测试链接联通性'))
            batch_op.add_column(sa.Column('config', sa.Text(), nullable=True, comment='其他配置'))
            batch_op.add_column(sa.Column('app_id', sa.Text(), nullable=True, comment='应用ID'))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('system_integration_extend', schema=None) as batch_op:
        batch_op.drop_column('app_id')
        batch_op.drop_column('config')
        batch_op.drop_column('test')
    # ### end Alembic commands ### 